#ifndef PLUGIN_H
#define PLUGIN_H

#include <defs/export.h>
#include <defs/global.h>
#include <core/entityobject.h>
#include <core/entitydeclarative.h>
#include <QtDeclarative>
#include <QtCore>
#include <extensions/context.h>

namespace Opl{
namespace Scripting {
namespace System {
namespace IO {
class File;
};
};
};
};

namespace Optra {

namespace Extensions{

O_PRIVATE_DECLARE(Plugin);

/*!
          Class represent base eztension with can be plugin or application.
          Walid extensions file types are:
          one - Optra Native Extension
          ona - Optra Native Application
          ose - Optra Script Extension
          osa - Optra Script Application
          ode - Optra Declaratice Extension
          oda - Optra Declarative Application
          */
class EXTENSIONS_EXPORT Plugin : public Opl::Core::EntityObject {
    Q_OBJECT
    Q_PROPERTY(Type type READ type)
    Q_PROPERTY(Area area READ area WRITE setArea)
    Q_PROPERTY(bool valid READ valid)
    Q_PROPERTY(QString errorString READ errorString)
    Q_PROPERTY(ContextPtr context READ context)
    Q_PROPERTY(QString name READ name WRITE setName)
    //Q_PROPERTY()
public:

    static QString ExtNativeExtension;
    static QString ExtNativeApplication;

    static QString ExtScriptExtension;
    static QString ExtScriptApplication;

    static QString ExtDeclarativeExtension;
    static QString ExtDeclarativeApplication;

    enum Type {
        undefined,
        extension,
        application
    };
    Q_ENUMS(Type)

    enum Area {
        Gui,
        Ghost
    };
    Q_ENUMS(Area)

    bool valid();
    Type type()const;

    const QString& name()const;
    void setName(const QString& value);

    Area area()const;
    void setArea(Area area);

    const QString& errorString()const;

    void setContext(const ContextPtr& ctx);
    const ContextPtr& context()const;

    virtual QString toString();


    Plugin();
    Plugin(Type type, const ContextPtr& ctx, Opl::Core::EntityObject *parent = 0);
    virtual ~Plugin();

    //Q_INVOKABLE virtual bool registerClass(Opl::Scripting::System::IO::File* file) = 0;

public slots:
    virtual void Setup(Type type, const ContextPtr& ctx);
    virtual void Start();

protected:
    void setValid(bool state);
    void setErrorString(const QString& error);
private:
    O_PRIVATE_DECLARE_MEMBER(Plugin)
};

}}
QML_DECLARE_TYPE(Optra::Extensions::Plugin)
#endif // PLUGIN_H

